package com.aplink.generic.util.validation;

import android.widget.DatePicker;

import java.util.Calendar;

public class CustomeDate extends ValidationBase {

    public CustomeDate() {
        this.ErrorMessage = "";
    }

    public CustomeDate( String errormessage ) {
        this.ErrorMessage = errormessage;

    }

    @Override
    public boolean checkValidation( Object ctrlCompare ) {
        if ( ctrlCompare instanceof DatePicker ) {
            final int day = ( (DatePicker) ctrlCompare ).getDayOfMonth();
            final int month = ( (DatePicker) ctrlCompare ).getMonth();
            final int year = ( (DatePicker) ctrlCompare ).getYear();

            final Calendar calendar = Calendar.getInstance();
            calendar.set( year, month, day );

            // get current date time with Calendar()
            final Calendar currentCal = Calendar.getInstance();
            return currentCal.compareTo( calendar ) < 0;
        } else {
            return false;

        }
    }

}
